<?php
class SearchController extends mcz_Controller
{
    public function __construct()
    {
		if(!$_SESSION['obj']->isAuth())
		{
			header('location: ' . mczURL('/auth'));
			die;
		}
		$this->setLayout('layout');
    }
    public function indexAction()
    {
		$suggest = array();
        $metaphone = isset($_GET['metaphone']) ? true : false;
		if(isset($_GET['searchTerms']))
		{
			$limit  = isset($_GET['limit']) ? $_GET['limit'] : 20;
			$offset = isset($_GET['offset']) ? $_GET['offset'] : 0;
			$terms  = trim($_GET['searchTerms']);
			$res    = mcz_Tune::search($terms, $offset, $limit, $metaphone);
			$this->assignToLayout('title', T('Search results for') .
								  ' "' . $_GET['searchTerms'] . '"');
		}
		else
		{
			$res   = array('total' => 0, 'items' => array());
			$terms = '';
			$offset = 0;
			$limit = 30;
			$this->assignToLayout('title', T('Index search'));
		}
        $this->display('index', array(
									  'limit'         => $limit,
									  'offset'        => $offset,
                                      'searchResults' => $res,
                                      'searchTerms'   => $terms,
                                      'metaphone'     => $metaphone
                                      ));
    }
}